Skip to content

Conversation

@wboayue
Copy link
Owner

@wboayue wboayue commented Jan 1, 2026

Summary

Closes #340

  • Add StartupMessageCallback type for processing unsolicited messages during connection handshake
  • Add connect_with_callback() method to both async and sync Client
  • Messages like OpenOrder and OrderStatus received during startup are passed to callback instead of being discarded

Usage

use ibapi::{Client, StartupMessageCallback};
use ibapi::messages::IncomingMessages;
use std::sync::{Arc, Mutex};

let orders = Arc::new(Mutex::new(Vec::new()));
let orders_clone = orders.clone();

let callback: StartupMessageCallback = Box::new(move |msg| {
    match msg.message_type() {
        IncomingMessages::OpenOrder | IncomingMessages::OrderStatus => {
            orders_clone.lock().unwrap().push(msg);
        }
        _ => {}
    }
});

let client = Client::connect_with_callback("127.0.0.1:4002", 100, Some(callback)).await?;

Test plan

  • Added 8 unit tests for callback functionality
  • Existing connect() behavior unchanged (backwards compatible)
  • Clippy clean on all feature combinations
  • All tests pass (1 pre-existing flaky test unrelated to this PR)

Add connect_with_callback() to handle unsolicited messages like OpenOrder
and OrderStatus during connection handshake instead of discarding them.

- Add StartupMessageCallback type for processing startup messages
- Add connect_with_callback() to async and sync Client
- Update ConnectionProtocol trait to accept callback parameter
- Re-export StartupMessageCallback from crate root
Add Drop impl to MessageBusStub to clean up ORDER_UPDATE_SUBSCRIPTION_TRACKER
when stub is dropped. This prevents test isolation issues where memory
addresses are reused across tests.

Also add with_responses() constructor to work around Rust limitation
with struct literals using Default::default() when Drop is implemented.
@wboayue wboayue merged commit fcb9595 into main Jan 2, 2026
5 checks passed
@wboayue wboayue deleted the feature/startup-message-callback branch January 2, 2026 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Open Orders are not transmitted during startup

1 participant